package javabasics.task3;

import java.util.Scanner;
import java.util.Arrays;


public class Anagram{

  private static final String IS_ANAGRAM = "true";
  private static final String IS_NOT_ANAGRAM = "not";

  public static void main(String[] args){
	Scanner input = new Scanner(System.in);
    System.out.println("Input your words:");
    String firstWord = input.next();
    String secondWord = input.next();
    input.close();     

    System.out.print("Words are " + isAnagram(firstWord, secondWord) + " anagrams"); 
  } 

  private static String isAnagram(String temp1, String temp2){
    char[] temp1Chars = temp1.toCharArray();
    char[] temp2Chars = temp2.toCharArray();

    Arrays.sort(temp1Chars);
    Arrays.sort(temp2Chars);

    String temp1Sort = new String(temp1Chars);
    String temp2Sort = new String(temp2Chars);

    if (temp1Chars.length != temp2Chars.length || !(temp1Sort.equals(temp2Sort))) {
    	return IS_NOT_ANAGRAM;
    }
    return IS_ANAGRAM;
  }
}